package info.fitnesse.meeting;

import info.fitnesse.meeting.domain.Account;
import info.fitnesse.meeting.domain.Subscription;

import java.util.HashMap;
import java.util.Map;

import fit.ColumnFixture;

public class ColumnFixtureTest extends ColumnFixture {

	public int subscriptionId;

	public double realMinute;

	public Map<String, Account> accountMap = new HashMap();

	public Map<String, String> unitPriceMap = new HashMap();

	public Map<String, Subscription> subscriptionMap = new HashMap();

	private double totalprice;

	public ColumnFixtureTest(Map accountMap, Map subscriptionMap,
			Map unitPriceMap) {
		this.accountMap = accountMap;
		this.subscriptionMap = subscriptionMap;
		this.unitPriceMap = unitPriceMap;
	}

	public double checkMoney() {
		totalprice = getUnitPrice() * realMinute;
		return totalprice;
	}

	public double accountBalanceMoney() {
		Subscription subscription = (Subscription) subscriptionMap.get(String
				.valueOf(subscriptionId));
		Account account = (Account) accountMap.get(String.valueOf(subscription
				.getAccountId()));
		return getAccountBalance() - totalprice;
	}

	private double getUnitPrice() {
		Subscription subscription = (Subscription) subscriptionMap.get(String
				.valueOf(subscriptionId));
		String ruleId = String.valueOf(subscription.getRuleId());
		String unitPriceStr = (String) unitPriceMap.get(ruleId);
		return Double.parseDouble(unitPriceStr);
	}

	private double getAccountBalance() {
		Subscription subscription = (Subscription) subscriptionMap.get(String
				.valueOf(subscriptionId));
		Account account = (Account) accountMap.get(String.valueOf(subscription
				.getAccountId()));
		return account.getBalance();

	}
}
